package Array;

/**
 * 977.有序数组的平方
 * <a>https://leetcode.cn/problems/squares-of-a-sorted-array/description/</a>
 */
public class G977 {
    public int[] sortedSquares(int[] nums) {

        int left=0,right=nums.length-1;
        int [] result =new int[nums.length];
        int index = result.length-1;
        while (left<=right){
            if (nums[left]*nums[left]>nums[right]*nums[right]){
                result[index--]=nums[left]*nums[left];
                ++left;
            }else {
                result[index--]=nums[right]*nums[right];
                --right;
            }
        }
        return result;
    }
}
